<template>
	<view class="my">


		<view class="order-container" ref="area">

		</view>
		<view class="border">

		</view>
		<!-- <u-tabs :list="list1" @click="click1" lineColor="#75D65E" :current="current"></u-tabs> -->
		<view class="header-box">
			<view class="header">
				<view style="width: 100%;display: flex;justify-content: center;margin-top: 150rpx;"
					v-if="list.length==0">
					<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"></u-empty>
				</view>
				<view class="item" v-for="(item,index) in list" :key="index">
					<view class="top">
						<view class="time">
							<text>{{formatTimestamp(item.createtime)}}</text>
							<text style="color: red;margin-left: 20rpx;font-size: 24rpx;"
								v-if="item.pay_status=='3'">(已退款)</text>
						</view>
					</view>
					<view class="center">
						<image :src="'https://ba.fuliaoxx.com' + item.usedInfo.image" mode="" class="good"></image>
						<view class="detail">
							<view class="name">
								{{item.usedInfo.name}}
							</view>
							<view class="" style="color: #7F7F7F;font-size: 24rpx;">
								购买后请等待卖家联系
							</view>
							<view class="num">
								<view class="" style="color: #FC5D2B;">
									￥{{item.usedInfo.price}}
								</view>

								<view class="" style="font-weight: 600;font-size: 32rpx;padding-right: 20rpx;">
									<!-- 	×{{item.num}} -->
								</view>
							</view>
							<view class=""
								style="color: #FC5D2B;font-size: 24rpx;display: flex;justify-content: space-between;"
								v-if="item.quanInfo">
								<view class="" style="color: grey;">
									优惠
								</view> -{{item.quanInfo.price}}
							</view>
						</view>
					</view>
					<view class="bottom">
						<view class="" style="font-weight: 600;font-size: 32rpx;" v-if="item.quanInfo">
							￥{{roundUpToTwoDecimalPlaces(item.usedInfo.price * item.num - Number(item.quanInfo.price) )}}
						</view>
						<view class="" style="font-weight: 600;font-size: 32rpx;" v-else>
							￥{{item.usedInfo.price * item.num}}
						</view>
						<!-- 	<view class="btn" @click="toDetail(item)">
							查看
						</view> -->
					</view>
				</view>

			</view>
		</view>

	</view>

	</view>
</template>

<script>
	import {
		usedlist
	} from "@/request/api/goods.js"
	export default {
		data() {
			return {
				list: [],
				current: 0,
				list1: [{
					name: '待发货',
				}, {
					name: '已发货',
				}, {
					name: '已完成'
				}]
			}
		},

		onShow() {
			this.getList()
		},
		methods: {
			click1(e) {
				console.log(e)
				if (this.current == e.index) return;
				this.current = e.index;
				this.getList()
			},

			roundUpToTwoDecimalPlaces(num) {
				return Math.ceil(num * 100) / 100;
			},
			async getList() {
				this.list = [];
				let res = await usedlist();
				let cur = (this.current + 1).toString()
				let json = res.data.filter(item => item.pay_status == '2' || item.pay_status == '3');
				this.list = json;
			},

			formatTimestamp(timestamp) {
				// 创建 Date 对象
				const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒
				// 获取年份、月份、日期、小时、分钟、秒
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
				const day = String(date.getDate()).padStart(2, '0');
				const hour = String(date.getHours()).padStart(2, '0');
				const minute = String(date.getMinutes()).padStart(2, '0');
				const second = String(date.getSeconds()).padStart(2, '0');
				// 返回格式化的日期时间字符串
				return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
			},
			toDetail(item) {
				uni.navigateTo({
					url: "/pages/detail2/detail?item=" + JSON.stringify(item)
				})
			}
		}
	}
</script>

<style>
	page {
		height: 100%;
	}
</style>
<style scoped lang="scss">
	/deep/ .line {
		input {
			text-align: right !important;
		}
	}

	.my {
		height: 100%;
		box-sizing: border-box;

		.bg {
			position: fixed;
			width: 100%;
			background-color: #75D65E;
			height: 180rpx;
			top: 0;
			z-index: 1;
		}

		// .border {
		// 	position: fixed;
		// 	width: 100%;
		// 	background-color: #F8F8F8;
		// 	height: 80rpx;
		// 	top: 120rpx;
		// 	z-index: 999;
		// 	border-radius: 50rpx 50rpx 0 0;
		// }

		.header {
			position: relative;
			z-index: 1;
			margin: 0 30rpx;
			padding: 30rpx 20rpx;
			border-radius: 30rpx;
			box-sizing: border-box;
			// height: calc(100% - 30rpx);
			// overflow: auto;
			// background: #f8f8f8;

			.item {
				padding: 20rpx;
				border-radius: 20rpx;
				background-color: white;
				margin-bottom: 30rpx;
				box-shadow: 2rpx 6rpx 8rpx #e7e7e7;

				.top {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.time {
						display: flex;
						align-items: center;
						color: #616161;
						font-size: 24rpx;

						image {
							width: 20rpx;
							height: 20rpx;
							margin-right: 10rpx;
						}
					}

					.btn {
						background-color: #FBDB0C;
						padding: 12rpx 20rpx;
						font-size: 24rpx;
						border-radius: 20rpx;
					}
				}

				.center {
					display: flex;
					margin: 20rpx 0;

					image {
						width: 180rpx;
						height: 180rpx;
						border-radius: 10rpx;
						margin-right: 20rpx;
					}

					.detail {
						height: 180rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						flex: 1;
						padding: 6rpx 0;
						box-sizing: border-box;

						.num {
							display: flex;
							justify-content: space-between;
							align-items: center;
						}
					}
				}

				.bottom {
					display: flex;
					justify-content: space-between;
					align-items: center;
					color: #FD2A00;

					.btn {
						color: white;
						background: linear-gradient(to bottom, #75D65E, #75D65E);
						padding: 14rpx 32rpx;
						border-radius: 20rpx;

					}
				}
			}



		}



	}
</style>